import { ipcRenderer } from "electron";
import {
    FileReadOptions,
    FileWriteOptions,
    DirectoryOptions,
    DownloadOptions
} from "../../main/fileService";

const fileApi = {
    /**
     * 读取文件内容
     */
    read: (filePath: string, options?: FileReadOptions) => ipcRenderer.invoke('file:read', filePath, options),

    /**
     * 写入文件内容
     */
    write: (filePath: string, data: string, options?: FileWriteOptions) => ipcRenderer.invoke('file:write', filePath, data, options),

    /**
     * 追加内容到文件
     */
    append: (filePath: string, data: string, options?: FileWriteOptions) => ipcRenderer.invoke('file:append', filePath, data, options),

    /**
     * 检查文件或目录是否存在
     */
    exists: (filePath: string) => ipcRenderer.invoke('file:exists', filePath),

    /**
     * 创建目录
     */
    mkdir: (dirPath: string, options?: DirectoryOptions) => ipcRenderer.invoke('file:mkdir', dirPath, options),

    /**
     * 读取目录内容
     */
    readdir: (dirPath: string) => ipcRenderer.invoke('file:readdir', dirPath),

    /**
     * 删除文件
     */
    unlink: (filePath: string) => ipcRenderer.invoke('file:unlink', filePath),

    /**
     * 删除目录
     */
    rmdir: (dirPath: string, recursive?: boolean) => ipcRenderer.invoke('file:rmdir', dirPath, recursive),

    /**
     * 获取文件信息
     */
    stat: (filePath: string) => ipcRenderer.invoke('file:stat', filePath),

    /**
     * 复制文件
     */
    copy: (sourcePath: string, destPath: string) => ipcRenderer.invoke('file:copy', sourcePath, destPath),

    /**
     * 下载文件
     */
    download: (url: string, destPath: string, options?: DownloadOptions) => ipcRenderer.invoke('file:download', url, destPath, options),

    /**
     * 解压 ZIP 文件
     */
    unzip: (zipPath: string, destPath: string) => ipcRenderer.invoke('file:unzip', zipPath, destPath),
};

export default fileApi;